<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="User Name" v-model="listQuery.filterItem">
      </el-input>
      <el-button class="filter-item" type="primary"  icon="el-icon-search" @click="handleFilter">search</el-button>
      <el-button class="filter-item" type="primary"  @click="handleReyurn">return</el-button>
    </div>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label='Index' width="95">
        <template slot-scope="scope">
          {{ 1 + scope.$index + ((listQuery.page -1 ) * listQuery.limit) }}
        </template>
      </el-table-column>
      <el-table-column label="Employee Name">
        <template slot-scope="scope">
          {{scope.row.user_name}}
        </template>
      </el-table-column>
      <el-table-column label="Employee Number" width="200" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.employee_number}}</span>
        </template>
      </el-table-column>
      <el-table-column label="Organization Name" width="200" align="center">
        <template slot-scope="scope">
          {{scope.row.organization_name}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="Purchase Date" width="200">
        <template slot-scope="scope">
          <span>{{scope.row.purchase_date}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="Been Used Date" width="200">
        <template slot-scope="scope">
          <span>{{scope.row.last_used_date}}</span>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getResDetailUsageList } from '@/api/resource'

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      tempResource: {
        resources_name: '',
        type: '',
        total_amount: '',
        price: '',
        unit: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        show: 'Resource Using'
      },
      typeList: [{ 'type_name': 'Computer' }, { 'type_name': 'PC components' }],
      rules: {
      },
      total: null,
      listQuery: {
        page: 1,
        limit: 10,
        filterItem: null,
        type: null,
        status: null,
        sort: null
      },
      type: 'create',
      resources_id: null,
      importanceOptions: [1, 2, 3],
      sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }]
    }
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  created() {
    if (this.$route.params.type !== undefined) {
      this.resources_id = this.$route.params.resources_id
      this.type = this.$route.params.type
    }
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      getResDetailUsageList(this.listQuery, this.resources_id).then(response => {
        this.list = response.dataList
        this.total = response.total
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleFilter() {
      this.getList()
    },
    handleReyurn(){
      this.$router.push({
        name: 'QueryResources',
        param: {

        }
      })
    }
  }
}
</script>
